#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;

int n, m, l[N], r[N], pot[N], cnt, ans, id[N];
priority_queue < int , vector < int > , greater < int > > q;

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in; rep(i, 1, n) l[i] = in, r[i] = in, id[i] = i;
	int cur = 1; sort(id + 1, id + n + 1, [](int a, int b) { return l[a] == l[b] ? r[a] > r[b] : l[a] < l[b]; });
	rep(i, 1, n) {
		int x = id[i]; q.push(r[x]);
		if(cur <= m && cur <= l[x]) cur++;
		else pot[++cnt] = q.top(), q.pop();
	}
	int tcur = cur - 1; cur = m;
	sort(pot + 1, pot + cnt + 1);
	per(i, cnt,  1) {
		if(cur > tcur && cur >= pot[i]) cur--;
		else ans++;
	} cout << ans << endl;
	return 0;
}
